#include "variable.hpp"


void variable_container::set(std::string name, value val)
{
    for(unsigned u = 0; u < list_of_variables.size(); u++)
    {
        if(list_of_variables[u].name == name)
        {
            list_of_variables[u].val = val;
            return;
        }
    }
    variable v;
    v.name = name;
    v.val = val;
    list_of_variables.push_back(v);
}

value variable_container::get(std::string name)
{
    for(unsigned u = 0; u < list_of_variables.size(); u++)
    {
        if(list_of_variables[u].name == name)
        {
            return list_of_variables[u].val;
        }
    }
    variable var;
    var.name = name;
    if(!name.empty() and name[(name.size()-1)] == '$')
    {
        value val("");
        var.val = val;
    }
    else
    {
        value val(0.0);
        var.val = val;
    }
    list_of_variables.push_back(var);
    return var.val;
}
